Introduction
Previous to version 3.2, to create an axis tick representing a value such as the average of the plotted data, the value had to be calculated, then, an axis tick was manually added to the axis. This process has now been simplified down to one simple line of code.
Calculated Axis Tick
The following code adds a calculated tick to an axis.
[C#]
Chart.YAxis.AddCalculatedTick(Calculation.Average);
[Visual Basic]
Chart.YAxis.AddCalculatedTick(Calculation.Average)
As you can see, this code does not specify any data to perform the calculation on. In this case, the data plotted on the axis is calculated.
Data Specific
A calculation based on only one series of the data shown on an axis is often desired. When this is the case, a single series or any number of series can be specified to base the calculation on.
The following code demonstrates specifying a series:
[C#]
Chart.YAxis.AddCalculatedTick(Calculation.Average, mySeries);
[Visual Basic]
Chart.YAxis.AddCalculatedTick(Calculation.Average, mySeries)
Using a template
The resulting axis tick will show the calculated value, however, if additional formatting or textual modifications are required, a template can be specified. The '%Value' token in the template will be replaced with the resulting value. The following examples demonstrate template usage.
[C#]
Chart.YAxis.AddCalculatedTick("<%Value,Currency>", Calculation.Average);
Chart.YAxis.AddCalculatedTick("Average: %Value", Calculation.Average);
// Resulting Ticks:
// $123
// Average: 123
[Visual Basic]
Chart.YAxis.AddCalculatedTick("<%Value,Currency>", Calculation.Average)
Chart.YAxis.AddCalculatedTick("Average: %Value", Calculation.Average)
' Resulting Ticks:
' $123
' Average: 123
Calculated Ticks of Shadow Axes
Calculated axis ticks can also be generated for shadow axes. Despite the data not being bound to the actual axis, a shadow axis will base it's calculations on the parent axis' data.
A common task could be to have an original axis show the scale, and a shadow axis on the other side of the chart can show the calculated axis ticks as shown below.
[C#]
Axis axisReplica = Chart.XAxis.Calculate("Replica",true,Orientation.Right);
axisReplica.AddCalculatedTick(Calculation.Average);
Chart.AxisCollection.Add(axisReplica);
[Visual Basic]
Dim axisReplica As Axis = Chart.XAxis.Calculate("Replica",True,Orientation.Right)
axisReplica.AddCalculatedTick(Calculation.Average)
Chart.AxisCollection.Add(axisReplica)
Sample: AxisShadowCalculatedTicks.aspx |